package com.washmadam.service.controller.cms.customer.user;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.washmadam.service.common.base.BaseController;
import com.washmadam.service.common.base.RequestDTO;
import com.washmadam.service.common.base.ResponseDTO;
import com.washmadam.service.common.constants.Constant;
import com.washmadam.service.db.dto.Customer;
import com.washmadam.service.db.request.query.CustomerQueryParam;
import com.washmadam.service.service.customer.CustomerQueryService;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(Constant.URL_PREFIX + "/cms/customer")
@Slf4j
public class CustomerUserCmsController extends BaseController {

	@Autowired
	CustomerQueryService customerQueryService;
	/**
	 * 
	 * @param 会员列表
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/getCustomerList")
	public String getCustomerList(@RequestBody RequestDTO req, HttpServletRequest request) {
		try {
			log.info("【会员列表】请求参数 data:{}", req.getData());
			if (req.getData() == null) {
				return ResponseDTO.fail("参数缺失", null);
			}
			CustomerQueryParam requestParam = JSONObject.parseObject(JSON.toJSONString(req.getData()),
					CustomerQueryParam.class);
			PageInfo<Customer> result = customerQueryService.getCustomerList(requestParam);
			log.info("【会员列表】调用成功:result;{}", result);
			return ResponseDTO.success(result);
		} catch (Exception e) {
			log.error("【会员列表】异常，{}", e);
			return ResponseDTO.fail("请求异常:" + e.getMessage(), null);
		}
	}
}
